package outViewMonteCarlo;

import java.awt.*;

/**
 * 〈一句话功能简述>
 * 〈没有试图通过蒙特卡洛推导出 Pi 的值〉
 *
 * @Author 17505
 * @Create 2021/6/8
 * @Since 1.0.0
 */
public class MonteCarloExperiment {

    private int squareSize;
    private int N;

    public MonteCarloExperiment(int squareSize, int n) {
        if (squareSize <= 0 || n <= 0) {
            throw new IllegalArgumentException("squareSize or N must larger this ZOR");
        }

        this.squareSize = squareSize;
        N = n;
    }

    public void run() {
        Circle circle = new Circle(squareSize / 2, squareSize / 2, squareSize / 2);
        MonteCarloPiData data = new MonteCarloPiData(circle);
        for (int i = 0; i < N; i++) {
            if (i % 100 == 0) {
                System.out.println(data.estimatePi());
            }
            int x = (int) (Math.random() * squareSize);
            int y = (int) (Math.random() * squareSize);

            data.addPoint(new Point(x, y));
        }

    }

    public static void main(String[] args) {
        int squareSize = 800;
        int N = 10000000;
        new MonteCarloExperiment(squareSize, N).run();
    }

}